<template>
    <div class="modifyCourse">
        <el-form :model="shopMsgFrom" label-width="80px" :rules="rules" ref="ruleForm">
            <el-form-item label="营业执照" >
                <el-upload
                        class="avatar-uploader"
                        action="http://192.168.1.42:82/system/tbBusiness/upload"
                        :show-file-list="false"
                        :on-success="handleAvatarSuccess"
                        :before-upload="beforeAvatarUpload"
                        style="width: 400px">
                    <img v-if="shopMsgFrom.license" :src="shopMsgFrom.license" class="avatar">
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
            </el-form-item>
            <el-form-item label="店铺名" prop="name">
                <el-input v-model="shopMsgFrom.name" placeholder="店铺名" style="width: 400px" readonly="readonly" ></el-input>
            </el-form-item>
            <el-form-item label="地址" prop="address">
                <el-input v-model="shopMsgFrom.address" placeholder="地址" style="width: 400px"></el-input>
            </el-form-item>
            <el-form-item label="注册人" prop="b_name">
                <el-input v-model="shopMsgFrom.b_name" placeholder="店铺注册人" style="width: 400px" readonly="readonly"></el-input>
            </el-form-item>
            <el-form-item label="商品类型" prop="cid">
                <el-select v-model="shopMsgFrom.tid" placeholder="商品类型">
                    <el-option v-for="Type in goodsType" :label="Type.typename" :value="Type.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="店铺状态" prop="typename">
                <el-select v-model="shopMsgFrom.start" placeholder="店铺状态" >
                    <el-option label="营业" value="0"></el-option>
                    <el-option label="整顿" value="1"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="editFrom">修改</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    export default {
        name:'ModifyCourse',
        data () {
            return {
                goodsType:[],
                shopMsgFrom:{},
            }
        },
        created() {
            this.SearchGoodsType();
            this.initTable()
        },
        methods: {
            SearchGoodsType(){
                this.$http.post("/goods/goodsType/select").then(result=>{
                    this.goodsType = result.data.data;
                    console.log(this.goodsType)
                })
            },
            editFrom(){
                this.$http.post("/system/shop/updateShopMsgByBid",this.shopMsgFrom).then(result=>{
                    if(result.data.code==2000){
                        this.$message.success("修改成功")
                        this.initTable()
                    }else {
                        this.$message.error("修改失败")
                    }
                })
            },
            initTable(){
              this.$http.post("/system/shop/selectShopMsgByBid").then(result=>{
                   console.log(result)
                   this.shopMsgFrom = result.data.data[0]
                   console.log(this.shopMsgFrom)
              })
            },
            handleAvatarSuccess(res,file){
                this.shopMsgFrom.license = res.data
            },
            beforeAvatarUpload(file) {
                const isJPG = file.type === 'image/jpeg';
                const isLt2M = file.size / 1024 / 1024 < 2;

                if (!isJPG) {
                    this.$message.error('上传头像图片只能是 JPG 格式!');
                }
                if (!isLt2M) {
                    this.$message.error('上传头像图片大小不能超过 2MB!');
                }
                return isJPG && isLt2M;
            },
        },
    }
</script>

<style lang="scss">

</style>